BUUCTF Reverse WriteUp 3

ACTF rome

The x86 executable expects an ACTF{...} input. Inside the braces, it shifts uppercase and lowercase letters separately, then compares the 16 transformed characters with a hard-coded array. The name “rome” is a useful hint.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
int func()
{
int result; // eax
int inner[4]; // [esp+14h] [ebp-44h]
unsigned __int8 v2; // [esp+24h] [ebp-34h]
unsigned __int8 v3; // [esp+25h] [ebp-33h]
unsigned __int8 v4; // [esp+26h] [ebp-32h]
unsigned __int8 v5; // [esp+27h] [ebp-31h]
unsigned __int8 v6; // [esp+28h] [ebp-30h]
int v7; // [esp+29h] [ebp-2Fh]
int v8; // [esp+2Dh] [ebp-2Bh]
int v9; // [esp+31h] [ebp-27h]
int v10; // [esp+35h] [ebp-23h]
unsigned __int8 v11; // [esp+39h] [ebp-1Fh]
char res[17]; // [esp+3Bh] [ebp-1Dh]
int i; // [esp+4Ch] [ebp-Ch]

res[0] = 81;
res[1] = 115;
res[2] = 119;
res[3] = 51;
res[4] = 115;
res[5] = 106;
res[6] = 95;
res[7] = 108;
res[8] = 122;
res[9] = 52;
res[10] = 95;
res[11] = 85;
res[12] = 106;
res[13] = 119;
res[14] = 64;
res[15] = 108;
res[16] = 0;
printf("Please input:");
scanf("%s", &v2);
result = v2;
if ( v2 == 'A' )
{
result = v3;
if ( v3 == 'C' )
{
result = v4;
if ( v4 == 'T' )
{
result = v5;
if ( v5 == 'F' )
{
result = v6;
if ( v6 == '{' )
{
result = v11;
if ( v11 == '}' )
{
inner[0] = v7;
inner[1] = v8;
inner[2] = v9;
inner[3] = v10;
for ( i = 0; i <= 15; ++i )
{
if ( *(inner + i) > '@' && *(inner + i) <= 'Z' )
*(inner + i) = (*(inner + i) - 51) % 26 + 65;
if ( *(inner + i) > '`' && *(inner + i) <= 'z' )
*(inner + i) = (*(inner + i) - 79) % 26 + 97;
}
for ( i = 0; i <= 15; ++i )
{
result = res[i];
if ( *(inner + i) != result )
return result;
}
result = printf("You are correct!");
}
}
}
}
}
}
return result;
}

The transformation operates on one character at a time, so I tried the possible characters at each position and kept the one that matched:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import string
table = string.printable
res = [0] * 17
res[0] = 81;
res[1] = 115;
res[2] = 119;
res[3] = 51;
res[4] = 115;
res[5] = 106;
res[6] = 95;
res[7] = 108;
res[8] = 122;
res[9] = 52;
res[10] = 95;
res[11] = 85;
res[12] = 106;
res[13] = 119;
res[14] = 64;
res[15] = 108;
res[16] = 0;

def enc(x:str):
if x.isupper():
return (ord(x) - 51) % 26 + 65
if x.islower():
return (ord(x) - 79) % 26 + 97;
return ord(x)

flag = []
for i in range(16):
for ch in table:
if enc(ch) == res[i]:
flag.append(ch)
break;
print(''.join(flag))

Cae3ar_th4_Gre@t

CrackMe

This x86 executable is not packed. Its main function asks for an alphanumeric username and password, passes them to sub_401830, and combines that result with another check before printing a message:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
int wmain()
{
FILE *v0; // eax
FILE *v1; // eax
char v3; // [esp+3h] [ebp-405h]
char v4; // [esp+4h] [ebp-404h]
char v5; // [esp+5h] [ebp-403h]
char v6; // [esp+104h] [ebp-304h]
char v7; // [esp+105h] [ebp-303h]
char password; // [esp+204h] [ebp-204h]
char v9; // [esp+205h] [ebp-203h]
char username; // [esp+304h] [ebp-104h]
char v11; // [esp+305h] [ebp-103h]

printf("Come one! Crack Me~~~\n");
username = 0;
memset(&v11, 0, 0xFFu);
password = 0;
memset(&v9, 0, 0xFFu);
while ( 1 )
{
do
{
do
{
printf("user(6-16 letters or numbers):");
scanf("%s", &username);
v0 = (FILE *)sub_4024BE();
fflush(v0);
}
while ( !checkIsAlNum(&username) );
printf("password(6-16 letters or numbers):");
scanf("%s", &password);
v1 = (FILE *)sub_4024BE();
fflush(v1);
}
while ( !checkIsAlNum(&password) );
sub_401090(&username);
v6 = 0;
memset(&v7, 0, 0xFFu);
v4 = 0;
memset(&v5, 0, 0xFFu);
v3 = ((int (__cdecl *)(char *, char *))loc_4011A0)(&v6, &v4);
if ( sub_401830((int)&username, &password) )
{
if ( v3 )
break;
}
printf(&v4);
}
printf(&v6);
return 0;
}

I followed the program in OllyDbg as far as sub_401830, checking whether either input had been changed before the call.

image-20200810175727286

Neither had changed, so the interesting work must happen inside the function:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
bool __usercall check@<al>(int a1@<ebx>, int username, const char *password)
{
int i; // [esp+18h] [ebp-22Ch]
signed int data_idx; // [esp+1Ch] [ebp-228h]
signed int k; // [esp+28h] [ebp-21Ch]
unsigned int cnt; // [esp+30h] [ebp-214h]
char v8; // [esp+36h] [ebp-20Eh]
char encrypt1; // [esp+37h] [ebp-20Dh]
char iter1; // [esp+38h] [ebp-20Ch]
unsigned __int8 v11; // [esp+39h] [ebp-20Bh]
unsigned __int8 v12; // [esp+3Ah] [ebp-20Ah]
char v13; // [esp+3Bh] [ebp-209h]
int v14; // [esp+3Ch] [ebp-208h]
char data; // [esp+40h] [ebp-204h]
char v16; // [esp+41h] [ebp-203h]
char data2; // [esp+140h] [ebp-104h]
char v18; // [esp+141h] [ebp-103h]

data_idx = 0;
k = 0;
v12 = 0;
v11 = 0;
data2 = 0;
memset(&v18, 0, 0xFFu);
data = 0;
memset(&v16, 0, 0xFFu);
iter1 = 0;
cnt = 0;
i = 0;
while ( cnt < strlen(password) )
{
if ( isdigit(password[cnt]) )
{
encrypt1 = password[cnt] - '0';
}
else if ( isxdigit(password[cnt]) )
{
if ( *(*(__readfsdword(0x30u) + 24) + 12) != 2 )
password[cnt] = 0x22;
encrypt1 = (password[cnt] | 0x20) - 87;
}
else
{
encrypt1 = ((password[cnt] | 0x20) - 97) % 6 + 10;
}
iter1 = encrypt1 + 16 * iter1;
if ( !((cnt + 1) % 2) ) // 如果是是单数
{
*(&data + i++) = iter1;
a1 = i;
iter1 = 0;
}
++cnt;
} // data 为输入的8个转化为字节
// abcd1234 -> AB CD 12 34
while ( k < 8 )
{
v11 += table[++v12];
v13 = table[v12];
v8 = table[v11];
table[v11] = v13;
table[v12] = v8;
if ( *(__readfsdword(0x30u) + 104) & 0x70 )
v13 = v11 + v12;
*(&data2 + k) = table[(v8 + v13)] ^ *(&data + data_idx);
if ( *(__readfsdword(0x30u) + 2) & 0xFF )
{
v11 = -83;
v12 = 43;
}
sub_401710(&data2, username, k++);
data_idx = k;
if ( k >= (&data + strlen(&data) + 1 - &v16) )
data_idx = 0;
}
v14 = 0;
sub_401470(a1, &data2, &v14);
return v14 == 43924;
}

That decompilation is a mess. The first part seems to turn the password into bytes, while a table is repeatedly rearranged below it. I could not make the trace agree with my expectations until another writeup pointed out the anti-debugging check: the program behaves differently when a debugger is present.

At the end, data2 needs to equal dbappsec. To work backward from that comparison, I first simulated the changing 272-element table:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
data = [
0x5E, 0xBE, 0x4D, 0x43, 0x24, 0xEB, 0x58, 0xE4, 0xC2, 0x5C,
0xBD, 0xC4, 0xAB, 0x39, 0x1D, 0x73, 0x27, 0xD7, 0x88, 0xB8,
0xF6, 0xF9, 0x01, 0xF4, 0x6D, 0xEF, 0x00, 0x15, 0x8C, 0xD5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9, 0xA4, 0xF8, 0x08, 0xE1, 0xB0, 0xEC, 0xE9,
0xA9, 0x34, 0xDD, 0x57, 0x23, 0x87, 0xC7, 0xEE, 0x3B, 0x5B,
0x46, 0x69, 0x84, 0x86, 0x0E, 0x96, 0x78, 0xD1, 0xFD, 0xFF,
0x68, 0xBC, 0x63, 0xF3, 0xD6, 0xFC, 0x82, 0x3F, 0x92, 0x52,
0x6E, 0x5F, 0x22, 0xF1, 0x0A, 0x45, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00
]
data2 = 'dbappsec'
idx1, idx2, idx3, idx4 = 0,0,0,0

password = []
for i in range(8):
idx1 += 1
idx2 += data[idx1]
idx2 &= 0xff
idx3 = data[idx1]
idx3 &= 0xff
idx4 = data[idx2]
data[idx2] = idx3
data[idx1] = idx4
# idx3 = (idx1 + idx2) & 0xff
ch = data[(idx3 + idx4)&0xff] ^ ord(data2[i])
password.append(chr(ch))

print(password)

['N', 'µ', 'ó', '\x99', '#', '\x91', '¡', '®']: can anyone actually type that?

That result did not look like a password I could type. The XOR values depend on the debugger state but are otherwise fixed, so I went back to trace them individually.

0x7e 0x98 0xc9 0x95 0x10 0x6d 0xf3 0x67

Still unconvinced, I checked the same steps in OllyDbg.

0x2a, 0xd7, 0x92, 0xe9, 0x53, 0xe2, 0xc4, 0xcd

The debugger actually agrees with my simulation: ['N', 'µ', 'ó', '\x99', '#', '\x91', '¡', '®'].

Hang on—the program converts the input into bytes, so those values can be entered as hex: 4eb5f3992391a1ae.

That still did not seem to be enough: a later branch also XORs the value with the username. I tried accounting for that too:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import hashlib

data = [
0x5E, 0xBE, 0x4D, 0x43, 0x24, 0xEB, 0x58, 0xE4, 0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06, 0x07, 0x95, 0xD8, 0xFA, 0x66, 0x2A, 0x7E, 0x94, 0x0D,
0x48, 0x90, 0xCA, 0x04, 0xED, 0x67, 0xE5, 0x4F, 0x2C, 0x1F,
0x14, 0xC1, 0xC9, 0xA4, 0xF8, 0x08, 0xE1, 0xB0, 0xEC, 0xE9,
0xA9, 0x34, 0xDD, 0x57, 0x23, 0x87, 0xC7, 0xEE, 0x3B, 0x5B,
0x46, 0x69, 0x84, 0x86, 0x0E, 0x96, 0x78, 0xD1, 0xFD, 0xFF,
0x68, 0xBC, 0x63, 0xF3, 0xD6, 0xFC, 0x82, 0x3F, 0x92, 0x52,
0x6E, 0x5F, 0x22, 0xF1, 0x0A, 0x45, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00
]
data2 = 'dbappsec'
username = 'welcomebeijing'
idx1, idx2, idx3, idx4 = 0,0,0,0

password = []
for i in range(8):
idx1 += 1
idx2 += data[idx1]
idx2 &= 0xff
idx3 = data[idx1]
idx3 &= 0xff
idx4 = data[idx2]
data[idx2] = idx3
data[idx1] = idx4
# idx3 = (idx1 + idx2) & 0xff
ch = data[(idx3 + idx4)&0xff] ^ ord(data2[i])
ch ^= ord(username[i])
password.append(hex(ch))


print(password)


39d09ffa4cfcc4cc passes my test, but neither the MD5 of the bytes nor the MD5 of that text is accepted as the answer.

image-20200810225935016

Why? I have already closed IDA and OllyDbg!

An online lookup gave me d2be2981b84f2a905669995873d6a36c, the MD5 of my earlier value, 4eb5f3992391a1ae.

That one is accepted! Apparently the username-XOR branch is not executed in the relevant run. What a strange challenge.

firmware

This is router firmware, a subject I had not studied. After trying tutorials and reinstalling binwalk according to the official instructions, I found a file called backdoor under /tmp and inspected it.

It is UPX-packed. After unpacking, the long main function confirms it is a backdoor.

The connection routine identifies the backdoor’s server address. Its connection code and endpoint are omitted here; they are part of the malware sample.

xxor

The Linux x86-64 binary asks for six integers, encrypts them in pairs, and then checks the resulting values. It even tells us to convert the input to hex and join it at the end:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
__int64 __fastcall main(__int64 a1, char **a2, char **a3)
{
signed int i; // [rsp+8h] [rbp-68h]
signed int j; // [rsp+Ch] [rbp-64h]
__int64 input[5]; // [rsp+10h] [rbp-60h]
__int64 encrypted[5]; // [rsp+40h] [rbp-30h]
unsigned __int64 v8; // [rsp+68h] [rbp-8h]

v8 = __readfsqword(0x28u);
puts("Let us play a game?");
puts("you have six chances to input");
puts("Come on!");
input[0] = 0LL;
input[1] = 0LL;
input[2] = 0LL;
input[3] = 0LL;
input[4] = 0LL;
for ( i = 0; i <= 5; ++i )
{
printf("%s", "input: ", (unsigned int)i);
__isoc99_scanf("%d", (char *)input + 4 * i);
}
encrypted[0] = 0LL;
encrypted[1] = 0LL;
encrypted[2] = 0LL;
encrypted[3] = 0LL;
encrypted[4] = 0LL;
for ( j = 0; j <= 2; ++j )
{
front_half = input[j];
back_half = *((_DWORD *)input + j * 2 + 1);
encrypt((unsigned int *)&front_half, &key);
LODWORD(encrypted[j]) = front_half;
*((_DWORD *)encrypted + j * 2 + 1) = back_half;
}
if ( (unsigned int)check(encrypted) != 1 )
{
puts("NO NO NO~ ");
exit(0);
}
puts("Congratulation!\n");
puts("You seccess half\n");
puts("Do not forget to change input to hex and combine~\n");
puts("ByeBye");
return 0LL;
}

Each pair of 32-bit inputs occupies one 64-bit slot. After encrypt transforms the pairs, check determines whether they match the required result. I started with that final check.

Here is check:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
signed __int64 __fastcall check(_DWORD *a1)
{
signed __int64 result; // rax

if ( a1[2] - a1[3] != 0x84A236FFLL || a1[3] + a1[4] != 0xFA6CB703LL || a1[2] - a1[4] != 0x42D731A8LL )
{
puts("Wrong!");
result = 0LL;
}
else if ( *a1 != 0xDF48EF7E || a1[5] != 0x84F30420 || a1[1] != 0x20CAACF4 )
{
puts("Wrong!");
result = 0LL;
}
else
{
puts("good!");
result = 1LL;
}
return result;
}

The comparisons amount to a small system of equations. A calculator would do, but this is a good excuse to install Z3 for later challenges.

[x = 3774025685, y = 1548802262, z = 2652626477]

The six encrypted numbers are:

a = {0xDF48EF7E, 0x20CAACF4, 0xe0f30fd5, 0x5c50d8d6, 0x9e1bde2d, 0x84F30420}

With those six target values in hand, I wrote a Java program to reverse the transformation:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60

import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.Arrays;

public class Leet {
public static void main(final String[] args) throws Exception {
final Solution l = new Solution();
int[] cipher = {0xDF48EF7E, 0x20CAACF4, 0xe0f30fd5, 0x5c50d8d6, 0x9e1bde2d, 0x84F30420};
ArrayList<Integer> res = new ArrayList<>();
ArrayList<Integer> cip = new ArrayList<>();
for(int i=0; i<cipher.length; i+=2){
int[] arr = l.decry(cipher[i], cipher[i+1]);
res.add(arr[0]);
res.add(arr[1]);
int[] c = l.encry(arr[0], arr[1]);
cip.add(c[0]);
cip.add(c[1]);
}
System.out.println(res);
for(int x: res){
System.out.print(Integer.toHexString(x));
System.out.print(",");
}
System.out.println();
System.out.println(cip);
for(int x: cip){
System.out.print(Integer.toHexString(x));
System.out.print(",");
}
System.out.println();
System.out.println(Arrays.toString(cipher));
}
}

class Solution {
int[] decry(int num1, int num2){
int[] key = {2, 2, 3, 4};
int magic = 0x458bcd42;
int delta = magic * 0x40;
for(int i=0; i<=0x3f; i++){
num2 -= (num1 + delta + 20) ^ ((num1 << 6) + key[2]) ^ ((num1 >> 9) + key[3]) ^ 0x10;
num1 -= (num2 + delta + 11) ^ ((num2 << 6) + key[0]) ^ ((num2 >> 9) + key[1]) ^ 0x20;
delta -= magic;
}
return new int[] {num1, num2};
}

int[] encry(int num1, int num2){
int[] key = {2, 2, 3, 4};
int delta = 0;
for (int i = 0; i <= 0x3F; ++i )
{
delta += 0x458BCD42;
num1 += (num2 + delta + 11) ^ ((num2 << 6) + key[0]) ^ ((num2 >> 9) + key[1]) ^ 0x20;
num2 += (num1 + delta + 20) ^ ((num1 << 6) + key[2]) ^ ((num1 >> 9) + key[3]) ^ 0x10;
}
return new int[] {num1, num2};
}
}

[-698534522, -1541066437, 1578206992, -287775654, 1339222190, -130761337] is incorrect.

The negative values are a clue: Java’s int is signed. I rewrote the calculation in C to handle the values as needed:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#include <stdio.h>

void decry(unsigned int num1,unsigned int num2, unsigned int* res){
int key[] = {2, 2, 3, 4};
int magic = 0x458bcd42;
int delta = magic * 0x40;
int i = 0;
for(i=0; i<=0x3f; i++){
num2 -= (num1 + delta + 20) ^ ((num1 << 6) + key[2]) ^ ((num1 >> 9) + key[3]) ^ 0x10;
num1 -= (num2 + delta + 11) ^ ((num2 << 6) + key[0]) ^ ((num2 >> 9) + key[1]) ^ 0x20;
delta -= magic;
}
res[0] = num1;
res[1] = num2;
}

int main(){
unsigned int res[2] = {0, 0};
unsigned int cipher[6] = {0xDF48EF7E, 0x20CAACF4, 0xe0f30fd5, 0x5c50d8d6, 0x9e1bde2d, 0x84F30420};
int i = 0;
for(i = 0; i<6; i+=2){
unsigned num1 = cipher[i];
unsigned num2 = cipher[i+1];
decry(num1, num2, res);
printf("%x, %x,", res[0], res[1]);
}
}

666c61, 677b72,655f69, 735f67,726561, 74217d

Convert the hex to a string: flag{re_is_great!}.

That completes all of the one-point BUUCTF challenges. Celebration! ★,°:.☆( ̄▽ ̄)/$:.°★ 。